<?php

namespace catchAdmin\phone\model;

class Notice extends \catchAdmin\model\Notice
{

    ######################################## 显示 ################################################

    public function indexData($param)
    {
        $app = $this
            ->where('wechat_user_id', $this->getLoginId())
            ->order('id', 'desc');

        $list = $this->indexDataCC($param, $app);

        foreach ($list['list'] as $k => $v) {
            $v['content'] = mb_substr($v['content'], 0, 30);

            $list['list'][$k] = $v;
        }

        $list['no_read'] = \catchAdmin\model\Notice::where('wechat_user_id', $this->getLoginId())
            ->where('read_time', 0)
            ->count() ?? 0;

        return $list;
    }


    /**
     * 已读
     */
    public function read($param)
    {
        $this->saveDataCC([
            'id'        => $param['id'],
            'read_time' => time(),
        ]);

        return self::where(['id' => $param['id']])
            ->find();
    }

}
